package com.magic.himalaya.utils;

import com.magic.himalaya.base.BaseFragment;
import com.magic.himalaya.fragments.HistoryFragment;
import com.magic.himalaya.fragments.RecommendFragment;
import com.magic.himalaya.fragments.SubscriptionFragment;

import java.util.HashMap;
import java.util.Map;
/**
 * @description: 程序进入后 主页面 三个页面调用使用缓存方式
 */
public class FragmentCreator {

    public final static int INDEX_RECOMMEND = 0;
    public final static int INDEX_SUBSCRIPTION = 1;
    public final static  int INDEX_HISTORY = 2;

    public final static  int PAGE_COUNT = 3;

    public static Map<Integer, BaseFragment> sCache = new HashMap<>();

    public static  BaseFragment getFragment(int index){
        BaseFragment baseFragment = sCache.get(index);
        if (baseFragment != null) {
            return baseFragment;
        }
        switch (index){
            case INDEX_RECOMMEND:
                baseFragment = new RecommendFragment();
                break;
            case INDEX_SUBSCRIPTION:
                baseFragment = new SubscriptionFragment();
                break;
            case INDEX_HISTORY:
                baseFragment = new HistoryFragment();
                break;
        }
        sCache.put(index,baseFragment);
        return baseFragment;
    }
}
